package com.example.binpacking.model;

import lombok.Data;

import java.io.Serializable;

/**
 * @author: bj
 * @Description: 全局的结果封装
 * @Date: 2023/3/29 17:21
 */
@Data
public class Result implements Serializable {
    private Integer code;// 200正常，非200异常
    private String msg;
    private Object data;

    public static Result success(Object data) {
        return success(200, "y", data);
    }
//    public static Result fail(Object data) {
//        return success(200, "n", data);
//    }

    public static Result success(int code, String msg, Object data) {
        Result r = new Result();
        r.setCode(code);
        r.setMsg(msg);
        r.setData(data);
        return r;
    }

    public static Result fail(String msg) {
        return fail(200, msg, null);
    }

    public static Result fail(String msg, Object data) {
        return fail(400, msg, data);
    }

    public static Result fail(int code, String msg, Object data) {
        Result r = new Result();
        r.setCode(code);
        r.setMsg(msg);
        r.setData(data);
        return r;
    }
//    public static <T> Result<T> success(int code, String msg, T data) {
//        return new Result<>(code, msg, data);
//    }
//
//    public static <T> Result<T> fail(int code, String msg, T data) {
//        return new Result<>(code, msg, data);
//    }    public static <T> Result<T> success(int code, String msg, T data) {
//        return new Result<>(code, msg, data);
//    }
//
//    public static <T> Result<T> fail(int code, String msg, T data) {
//        return new Result<>(code, msg, data);
//    }

//    public static Result success() {
//        return success(200, "成功",data);
//    }
}
